package main

import (
	"fgo/advance/db/gorm/models"
	"github.com/google/martian/log"
)

func main() {
	log.SetLevel(log.Debug)
	db := models.NewDb()
	defer db.Close()

	////////////////// 错误处理
	var user models.User
	// SELECT * FROM `user`  WHERE (name = 'jinzhu') ORDER BY `user`.`id` ASC LIMIT 1
	if err := db.Where("name = ?", "jinzhu").First(&user).Error; err != nil {
		// 错误处理...
		log.Errorf("error: (%v)....", err)
	}
	//  SELECT * FROM `user`  WHERE (name = 'hello world') ORDER BY `user`.`id` ASC LIMIT 1
	if db.Where("name = ?", "hello world").First(&user).RecordNotFound() {
		log.Errorf("RecordNotFound.....")
	}
}
